<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${packPath}.entity.${sort.objName}">
<!--write start 请勿删除此标记, 此区域块内请勿做变动 -->
  <resultMap id="result${sort.objName}" type="${packPath}.entity.${sort.objName}">
  <#list metadatas as mt><#if mt.dataRestrict=="1"> <id property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="VARCHAR"/> </#if></#list>
      <#list metadatas as mt>
	    <#if mt.dataRestrict!="1">
	    <#if mt.dataType=="6">
	    <result property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="TIMESTAMP"/>
	    <#elseif mt.dataType=="1">
	    <result property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="INTEGER"/>
	    <#elseif mt.dataType=="2">
	     <result property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="BIGINT"/>
	    <#elseif mt.dataType=="3">
	    <result property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="DOUBLE"/>
	    <#else>
	    <result property="${mt.dataAttr}" column="${mt.dataShortName}" jdbcType="VARCHAR"/>
	    </#if>
	    </#if>
    </#list>
  </resultMap>

  <sql id="selectSql${sort.objName}">
     <#list metadatas as mt><#if mt.dataRestrict=="1"> ${mt.dataShortName}</#if></#list><#list metadatas as mt><#if mt.dataRestrict!="1">,${mt.dataShortName}</#if></#list>
  </sql>
  <sql id="selectSql${sort.objName}ById">
      select <#list metadatas as mt><#if mt.dataRestrict=="1"> ${mt.dataShortName}</#if></#list><#list metadatas as mt><#if mt.dataRestrict!="1">,${mt.dataShortName}</#if></#list> from ${sort.infoTableName}
      <#list metadatas as mt><#if mt.dataRestrict=="1"> WHERE  ${mt.dataShortName}=###${mt.dataAttr}}</#if></#list>
      <#if lhprimary??> WHERE ${lhprimary}</#if>
  </sql>
  <sql id="deleteSql${sort.objName}ById">
      DELETE FROM ${sort.infoTableName}
      <#list metadatas as mt><#if mt.dataRestrict=="1"> WHERE ${mt.dataShortName}=###${mt.dataAttr}}</#if></#list>
      <#if lhprimary??> WHERE ${lhprimary}</#if>
  </sql>
  <sql id="variableSql${sort.objName}">
<#list metadatas as mt><#if mt.dataRestrict=="1">###${mt.dataAttr},jdbcType=VARCHAR}</#if></#list><#list metadatas as mt><#if mt.dataRestrict!="1"><#if mt.dataType=="6">,###${mt.dataAttr},jdbcType=TIMESTAMP}<#elseif mt.dataType=="1">,###${mt.dataAttr},jdbcType=INTEGER}<#elseif mt.dataType=="2">,###${mt.dataAttr},jdbcType=BIGINT}<#elseif mt.dataType=="3">,###${mt.dataAttr},jdbcType=DOUBLE}<#else>,###${mt.dataAttr},jdbcType=VARCHAR}</#if></#if></#list>
  </sql>
  <sql id="updateSql${sort.objName}">
	 <trim prefix="SET" prefixOverrides=","><#list metadatas as mt> <#if mt.dataRestrict!="1" || mt.dataRestrict!="4">
	          <if test="${mt.dataAttr} != null">,${mt.dataShortName}=###${mt.dataAttr}}</if></#if></#list>
	       </trim>
	<#list metadatas as mt><#if mt.dataRestrict=="1"> WHERE ${mt.dataShortName}=###${mt.dataAttr}}</#if></#list>
	<#if lhprimary??> WHERE ${lhprimary}</#if>
  </sql>
  <sql id="whereSql${sort.objName}">
    where 1=1 
    <#list metadatas as mt><#if mt.dataType=="4" || mt.dataType=="5">
    <if test="${mt.dataAttr} != null and ${mt.dataAttr} != ''"> and ${mt.dataShortName}=###${mt.dataAttr}}</if>
    </#if></#list>
    </sql>
  <insert id="insert${sort.objName}" parameterType="${packPath}.entity.${sort.objName}">
       INSERT INTO ${sort.infoTableName} ( <include refid="selectSql${sort.objName}"/>
       ) VALUES ( <include refid="variableSql${sort.objName}"/>)
   </insert>
  <update id="update${sort.objName}" parameterType="${packPath}.entity.${sort.objName}">
       UPDATE ${sort.infoTableName}
       <include refid="updateSql${sort.objName}"/>
   </update>
  <delete id="deleteById" parameterType="java.util.Map">
      <include refid="deleteSql${sort.objName}ById"/>
   </delete>
  <select id="selectById" resultMap="result${sort.objName}" parameterType="java.util.Map">
       <include refid="selectSql${sort.objName}ById"/>
   </select>
  <select id="countByProperty" resultType="java.lang.Long"  parameterType="java.util.Map">
       SELECT count(*) FROM ${sort.infoTableName} <include refid="whereSql${sort.objName}"/>
   </select>
  <select id="selectByProperty" resultMap="result${sort.objName}"  parameterType="java.util.Map">
       SELECT <include refid="selectSql${sort.objName}"/> FROM ${sort.infoTableName} <include refid="whereSql${sort.objName}"/>
       <if test="orderby != null and orderby != ''"> order by ${r'${orderby}'}</if>
   </select>
   <!--write stop 请勿删除此标记 -->

</mapper>

